import { createRouter, createWebHashHistory } from 'vue-router'
import { sessionStorage } from '../utils/storage'

const routes = [
  {
    path: '/',
    // redirect: {
    //   path: '/login',
    // },
    component: () => import('@/components/layout/layout.vue'),
    children: [
      {
        path: 'gateway',
        name: '工作门户',
        component: () => import('@/pages/gateway/gateway.vue'),
      },
      {
        path: 'perception',
        name: '感知监测',
        children: [
          {
            path: 'water',
            name: '水位流量监管',
            component: () => import('@/pages/perception/water.vue'),
          },
          {
            path: 'video',
            name: '视频监控',
            component: () => import('@/pages/perception/video.vue'),
          },
        ],
      },
    ],
  },
  {
    path: '/login',
    component: () => import('@/components/login/index.vue'),
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') next()

//   const tokenStr = sessionStorage.get('token',false)
//   // 增加判断条件
//   if (!tokenStr && to.path !== '/login'){
//     console.log(tokenStr)
//     return next('/login')
//   }
//   next()
// })
export default router
